import requests
from HealthCommission.Health_Commission_request import TypeRunSpider


def is_proxy_available(proxy_ip):
    try:
        proxy_url = f'http://{proxy_ip}'
        proxies = {"http": proxy_url, "https": proxy_url}

        # 使用代理发送请求
        orun = TypeRunSpider('', '', '', '', '', '')
        orun.run()
    except (requests.exceptions.RequestException, ConnectionError):
        return False


def main():
    header = {
        "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36",
        "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9",
        "Accept-Encoding": "gzip, deflate",
        "Accept-Language": "zh-CN,zh;q=0.9,en;q=0.8",
    }
    ip_pool = requests.get(
        "https://dps.kdlapi.com/api/getdps/?secret_id=oni95gpaagm4sdjxuytp&signature=s3256ono23tx5ydz44y07uqi8lnmrk3l&num=1&pt=1&format=json&sep=1&dedup=1").json()['data']['proxy_list']
    print(ip_pool)
    for proxy_ip in ip_pool:
        if is_proxy_available(proxy_ip):
            print(f"Proxy {proxy_ip} is available.")
        else:
            print(f"Proxy {proxy_ip} is not available.")


if __name__ == "__main__":
    main()
